import { BaseSkill } from '../BaseSkill';
import { DamageType, SkillType } from '../../types';
import { General } from '../../models/General';
import { Battle } from '../../models/Battle';

export class LieHuoFenYing extends BaseSkill {
  private readonly DAMAGE_RATIO = 0.8;  // 80% 智力伤害

  constructor() {
    super(
      'lieHuoFenYing',
      '烈火焚营',
      SkillType.Active,
      DamageType.Strategy,
      0.5,        // 50% 触发概率
      3,          // 3回合CD
      1           // 1回合持续
    );
  }

  execute(source: General, battle: Battle): void {
    if (!this.canUse() || Math.random() > this.probability) return;

    // 获取敌人并按兵力排序
    const enemies = battle.getEnemies(source)
      .sort((a, b) => a.troops - b.troops);

    // 计算基础伤害
    const baseDamage = source.attributes.intelligence * this.DAMAGE_RATIO;

    // 对所有敌人造成伤害
    enemies.forEach(enemy => {
      enemy.addEffect({
        type: 'strategyDamageBoost',
        value: baseDamage,
        duration: this.duration,
        stackable: true,
        source: this.id,
        timestamp: Date.now()
      });
    });

    this.startCooldown();
  }
}
